import request from "@/core/http/http"
// const bodyparser = require('body-parser');
// const axios = require("axios");
// const qs = require("qs");

export const GET_INDEX_CITY = "index/get_index_city"
export const GET_INDEX_DATA = "index/get_index_data"
export const SET_CURRENT_CITY = "city/set_current_city"
export const GET_HOTSRECOMMEND_DATA = "index/get_hotsrecommend_data"
export const GET_TOURRECOMMEND_DATA = "index/get_tourrecommend_data"
export const GET_FLOORSHOW_DATA = "index/get_floorshow_data"
export const GET_THEATER_DATA = "theater/get_theater_data"
export const GET_RECOMMDED_DATA = "theater/get_theater_data"

const action = (val, type) => {
    return {
        type,
        val
    }
}
//城市列表
export const loadCityDataAsync = (dispatch) => {
    return () => {
        request({
            method: "get",
            url: "/city/city/getSortedCityList?version=6.0.1&referer=2"
        }).then(res => {
            dispatch(action(res, GET_INDEX_CITY))
        })
    }
}
// /home/index/getClassifyHome?city_id=5&abbreviation=BJ&version=6.0.1&referer=2
//头部数据
export const loadIndexDataAsync = (dispatch, currentCity) => {
    // let actionData = {
    //     url: "https://api.juooo.com/home/index/getClassifyHome",
    //     params: {
    //         id: currentCity.city_id,
    //         abbreviation: currentCity.abbreviation || "",
    //         "version": " 6.0.3",
    //         "referer": "2"
    //     },
    //     headers: {
    //         "AUTHORIZATION": "g215vlnrcgqt1197i1h0i3qg26",
    //         "Origin": "https://m.juooo.com",
    //         "Referer": "https://m.juooo.com/",

    //     }
    // }
    // axios({
    //     method: "post",
    //     url: "/napis",
    //     data: qs.stringify(actionData)

    // }).then((res) => {
    //     console.log(res);
    //     res.currentCity = currentCity
    //     dispatch(action(res, GET_INDEX_DATA))

    // })

    return ()=>{ 
        request({
            method:"get",
            url:"/home/index/getClassifyHome",
            params:{
                id:currentCity.city_id,
                abbreviation:currentCity.abbreviation||"",  
                version:"6.0.1",
                referer:'1'
            }
        }).then(res=>{
            res.currentCity=currentCity
            dispatch(action(res,GET_INDEX_DATA))
        })
    }
}

// 热门演出接口

export const loadHotsrecommendAsync = (dispatch, id) => {

    return () => {
        request({
            method: "get",
            url: "/home/index/getHotsRecommendList",
            params: {
                city_id: id,
                version: "6.0.3",
                referer: '2'
            }
        }).then(res => {
            dispatch(action(res, GET_HOTSRECOMMEND_DATA))
        })
    }
}
//巡回演出
export const loadTourrecommendAsync = (dispatch, id) => {
    

    return () => {
        request({
            method: "get",
            url: "/home/index/getTourRecommendList",
            params: {
                city_id: id,
                version: "6.0.3",
                referer: '2'
            }
        }).then(res => {
            dispatch(action(res, GET_TOURRECOMMEND_DATA))
        })
    }
}

//演唱会  音乐剧 ...数据   /home/index/getFloorShow?city_id=0&version=6.0.3&referer=2
export const loadFloorShowAsync = (dispatch, id) => {
    return () => {
        request({
            method: "get",
            url: "/home/index/getFloorShow",
            params: {
                city_id: id,
                version: "6.0.3",
                referer: '2'
            }
        }).then(res => {
            let rel=res.data.data;
            dispatch(action(rel, GET_FLOORSHOW_DATA))
        })
    }
}

// 为你推荐数据
export const loadGetRecommendAsync = (dispatch,data) => {
    return () => {
        console.log(data);
        
        request({
            method: "get",
            url: "/home/index/getRecommendShow",
            params: {
                cityAdd: data.abbreviation,
                page:data.page,
                version: "6.0.3",
                referer: '2'
            }
        }).then(res => {
            
            let rel=res.data.data.recommend_show_list;
            // console.log(res.data.data.recommend_show_list);
            // console.log(rel);
            dispatch(action(rel, GET_RECOMMDED_DATA))
        })
    }
}

//剧院数据
export const loadTheaterDataAsync=(dispatch)=>{
    return ()=>{
        request({
            method: "get",
            url: "/theatre/index/getTheatreList",
            params: {
                page: 1,
                version: "6.0.3",
                referer: '2'
            }
        }).then(res => {
            // console.log(res);
            
            dispatch(action(res, GET_THEATER_DATA))
        })

    }
}